import { locShare, locUserInfo } from '@/utils/locStore/data'
export default {
  data() {
    return {
      shareMaterialInfo: {},
      shareInfo: {
        type: '',
        id: '',
        name: ''
      }
    }
  },
  // #ifdef MP-WEIXIN || MP-ALIPAY
  async onShareAppMessage() {
    // const shareMaterialInfo = await shareApi.getShareMaterial()
    if (!this.$auth.getIslogin()) {
      this.$msg.toast('请先登录后在分享')
      this.$tools.navigateTo('/pages/login/index')
      return
    }
    const res = this.handleShareQuery()
    const path = res.path
    // #ifdef MP-ALIPAY
    // path = 'pages/index/index'
    // #endif
    return {
      title: '这里购票好便宜', // shareMaterialInfo.name ||
      path
      // imageUrl: shareMaterialInfo.shareImage[0] || ''
    }
  },
  // #endif
  methods: {
    // #ifdef MP-WEIXIN || MP-ALIPAY
    handleShareQuery() {
      const whiteUrl = [
        'subPages/filmDetail/filmDetail',
        'subPages/selectFilm/selectFilm',
        'subPages/selectCinema/selectCinema',
        'pages/goodDetail/index'
      ]
      console.log(this.$tools.getCurrentPage(), '------')
      const cuttentRoute = this.$tools.getCurrentPage().cuttentRoute
      const options = this.$tools.getCurrentPage().options
      const url = whiteUrl.includes(cuttentRoute)
        ? this.$tools.getCurrentPage().cuttentRoute
        : ''
      const { shareKey, userName, nickName, headImg, memberId } =
        locUserInfo.get()
      console.log(memberId, 'memberId')
      const shareParams = {
        uId: shareKey,
        memberId,
        nickName,
        headImg,
        userName,
        showUser: '1'
      }
      console.log(options, '454545')
      if (options && options.mallCommodityId) {
        shareParams.id = options.mallCommodityId
      } else {
        shareParams.id = ''
      }

      locShare.set(shareParams)
      this.shareInfo = Object.assign({}, this.shareInfo, locShare.get(), {
        jumpUrl: '/' + url,
        opt: whiteUrl.includes(cuttentRoute)
          ? JSON.stringify(this.$tools.getCurrentPage().options).replace(
              /,/g,
              '-'
            )
          : ''
      })
      console.log(this.shareInfo, '===shareQuery')
      const { jumpUrl, shareQuery } = this.$auth.getShareInfo(this.shareInfo)
      console.log('shareQuery:', shareQuery, jumpUrl)
      this.$auth.getShareCount()
      return {
        path: `${jumpUrl}?sq=${shareQuery}`
      }
    }
    // #endif
  }
}
